package com.gopay.common.constants.autosettle;

import java.util.HashMap;
import java.util.Map;

/**
 * 自动结算对账标识
 * Created by dak.wang on 2017/8/15.
 */
public class AutoSettleCheckOrderConstants {

    /**
     * 对账来源-成功明细
     */
    public static final String CO_BANK_STATUS_SUCCESS = "01";

    /**
     * 对账来源-退回明细
     */
    public static final String CO_BANK_STATUS_RETURN = "02";


    /**
     * 对账结果-待对账
     */
    public static final String CO_STATUS_INIT = "00";

    /**
     * 对账结果-对平
     */
    public static final String CO_STATUS_EQUAL = "10";

    /**
     * 对账结果-存疑
     */
    public static final String CO_STATUS_DOUBT = "20";

    /**
     * 对账结果-差异
     */
    public static final String CO_STATUS_DIFF = "30";

    /**
     * 对账结果-待更新状态
     */
    public static final String CO_STATUS_WAIT_UPDATE = "40";

    /**
     * 对账结果-已人工处理
     */
    public static final String CO_STATUS_DONE = "99";

    /**
     * 对账结果明细-存疑短款
     */
    public static final String CO_DETAIL_DOUBT_SHORT = "21";

    /**
     * 对账结果明细-存疑长款
     */
    public static final String CO_DETAIL_DOUBT_LONG = "22";

    /**
     * 对账结果明细-单边短款
     */
    public static final String CO_DETAIL_SINGLE_SHORT = "31";

    /**
     * 对账结果明细-单边长款
     */
    public static final String CO_DETAIL_SINGLE_LONG = "32";

    /**
     * 对账结果明细-金额差异
     */
    public static final String CO_DETAIL_AMT_DIFF = "33";

    /**
     * 对账结果明细-成功明细
     */
    public static final String CO_DETAIL_SUCCESS = "41";

    /**
     * 对账结果明细-退回明细
     */
    public static final String CO_DETAIL_RETURN = "42";

    /**
     * 对账结果明细-无网银明细
     */
    public static final String CO_DETAIL_NONE = "43";

    /**
     * 对账结果明细-重复订单
     */
    public static final String CO_DETAIL_REPEAT = "44";

    /**
     * 对账结果明细-付款状态错误
     */
    public static final String CO_DETAIL_PAY_STAT_ERR = "45";

    /**
     * 对账结果明细-暂无差异
     */
    public static final String CO_DETAIL_NO_DIFFERENCE = "46";

    /**
     * 对账结果明细-未知
     */
    public static final String CO_DETAIL_UNKNOW = "99";

    /**
     * 对账状态-对账中
     */
    public static final String CO_DO_INIT = "03";

    /**
     * 对账状态-对账完成
     */
    public static final String CO_DO_SUCCESS = "01";

    /**
     * 对账状态-对账失败
     */
    public static final String CO_DO_FAILED = "02";

    /**
     * 农业银行
     */
    public static final String BANK_CODE_ABC = "ABC";

    /**
     * 中国银行
     */
    public static final String BANK_CODE_BOC = "BOC";

    /**
     * 建设银行
     */
    public static final String BANK_CODE_CCB = "CCB";

    /**
     * 招商银行
     */
    public static final String BANK_CODE_CMB = "CMB";

    /**
     * 工行当日
     */
    public static final String BANK_CODE_ICBC = "ICBC";

    /**
     * 工行往日
     */
    public static final String BANK_CODE_ICBC_PAST = "ICBC_PAST";

    /**
     * 文件处理状态 00-处理成功
     */
    public static final String DEAL_STATUS_SUCCESS = "00";

    /**
     * 文件处理状态 01-处理失败
     */
    public static final String DEAL_STATUS_FAIL = "01";

    /**
     * 文件处理状态 02-处理中
     */
    public static final String DEAL_STATUS_ONGOING = "02";
    /**
     *中行退回明细标识
     */
    public static final String BOC_RETRUN_IDENTIFY="代发退划";
    /**
     * 招行退回明细标识1
     */
    public static final String CMB_RETRUN_IDENTIFY1="代发时，合作方余款退还";
    /**
     * 招行退回明细标识2
     */
    public static final String CMB_RETRUN_IDENTIFY2="企业银行和应急模式业务被支付平台退回";


    private static Map<String, String> coBankStatusMap = new HashMap<String, String>();
    private static Map<String, String> coStatusMap = new HashMap<String, String>();
    private static Map<String, String> coDetailMap = new HashMap<String, String>();
    private static Map<String, String> bankCodeMap = new HashMap<>();
    private static Map<String, String> dealStatusMap = new HashMap<>();

    static {
        coBankStatusMap.put("01", "成功明细");
        coBankStatusMap.put("02", "退回明细");

        coStatusMap.put("00", "待对账");
        coStatusMap.put("10", "对平");
        coStatusMap.put("20", "存疑");
        coStatusMap.put("30", "差异");
        coStatusMap.put("40", "待更新状态");
        coStatusMap.put("99", "已人工处理");

        coDetailMap.put("21", "存疑短款");
        coDetailMap.put("22", "存疑长款");
        coDetailMap.put("31", "单边短款");
        coDetailMap.put("32", "单边长款");
        coDetailMap.put("33", "金额差异");
        coDetailMap.put("41", "成功明细");
        coDetailMap.put("42", "退回明细");
        coDetailMap.put("43", "无网银明细");
        coDetailMap.put("44", "重复订单");
        coDetailMap.put("45", "付款状态错误");
        coDetailMap.put("46", "暂无差异");

        dealStatusMap.put("00","处理成功");
        dealStatusMap.put("01","处理失败");
        dealStatusMap.put("02","处理中");
    }


    /**
     * 翻译对账来源
     *
     * @param type
     * @return
     */
    public static String getCoBankStatus(String type) {
        String ret = coBankStatusMap.get(type);
        return isNotBlank(ret) ? ret : "未知";
    }


    /**
     * 根据对账状态获取对账状态细分
     * @param type
     * @return
     */
    public static Map<String,String> getDtlbyStatus(String type){
        Map<String,String> dtlMap =new HashMap<>();
        if ("ALL".equals(type)) {
            dtlMap.put("21", "存疑短款");
            dtlMap.put("22", "存疑长款");
            dtlMap.put("31", "单边短款");
            dtlMap.put("32", "单边长款");
            dtlMap.put("33", "金额差异");
            dtlMap.put("41", "成功明细");
            dtlMap.put("42", "退回明细");
            dtlMap.put("43", "无网银明细");
            dtlMap.put("44", "重复订单");
            dtlMap.put("45", "付款状态错误");
            dtlMap.put("46", "暂无差异");
            return dtlMap;
        }
        if (coStatusMap.containsKey(type)) {
            switch (type){
                case CO_STATUS_DOUBT:{
                    //存疑
                    dtlMap.put("21", "存疑短款");
                    dtlMap.put("22", "存疑长款");
                    dtlMap.put("46", "暂无差异");
                    break;
                }
                case CO_STATUS_DIFF:{
                    //差异
                    dtlMap.put("31", "单边短款");
                    dtlMap.put("32", "单边长款");
                    dtlMap.put("33", "金额差异");
                    dtlMap.put("44", "重复订单");
                    break;
                }
                case CO_STATUS_WAIT_UPDATE:{
                    //待更新状态
                    dtlMap.put("41", "成功明细");
                    dtlMap.put("42", "退回明细");
                    dtlMap.put("43", "无网银明细");
                    dtlMap.put("45", "付款状态错误");
                    break;
                }
                case CO_STATUS_DONE:{
                    //已人工处理
                    dtlMap.put("21", "存疑短款");
                    dtlMap.put("22", "存疑长款");
                    dtlMap.put("31", "单边短款");
                    dtlMap.put("32", "单边长款");
                    dtlMap.put("33", "金额差异");
                    dtlMap.put("41", "成功明细");
                    dtlMap.put("42", "退回明细");
                    dtlMap.put("43", "无网银明细");
                    dtlMap.put("44", "重复订单");
                }
                default:{
                    break;
                }
            }
        }
        return dtlMap;
    }

    /**
     * 翻译对账结果
     *
     * @param type
     * @return
     */
    public static String getCoStatus(String type) {
        String ret = coStatusMap.get(type);
        return isNotBlank(ret) ? ret : "未知";
    }

    /**
     * 翻译对账结果明细
     *
     * @param type
     * @return
     */
    public static String getCoDetail(String type) {
        String ret = coDetailMap.get(type);
        return isNotBlank(ret) ? ret : "未知";
    }

    /**
     * 翻译文件处理结果
     * @param status
     * @return
     */
    public static String getDealStatus(String status){
        String res = dealStatusMap.get(status);
        return isNotBlank(res) ? res : "未知";
    }



    public static boolean isNotBlank(String s) {
        if (null != s) {
            return true;
        }
        return false;
    }
}
